package com.yinxin.thread.state;

/**
 * @author yinxin
 * @Title:
 * @Package
 * @Description:
 * @date 2022/1/714:56
 */
public class TestYield {
    public static void main(String[] args) {
        MyYield myYield = new MyYield();
        YouYield youYield = new YouYield();
        new Thread(myYield,"a").start();
        new Thread(youYield,"b").start();
    }
}
class MyYield implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        Thread.yield();//礼让
        System.out.println(Thread.currentThread().getName()+"线程停止执行");
    }
}

class YouYield implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        System.out.println(Thread.currentThread().getName()+"线程停止执行");
    }
}